package com.anlu.zk.simple;

import com.sun.org.apache.xpath.internal.operations.Or;
import org.apache.curator.framework.recipes.locks.InterProcessLock;

import java.util.List;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;

public class OrderService implements Runnable {

    //发令枪，模拟50个并发
    private static CountDownLatch countDownLatch = new CountDownLatch(50);
    private static OrderNumGenerater orderNumGenerater = new OrderNumGenerater();

    private static List<String> result = new Vector<>();

    @Override
    public void run() {
        countDownLatch.countDown();
        result.add(orderNumGenerater.getNumber());
    }


    public static void main(String[] args) {
        System.out.println("生成唯一的订单号");
        result.clear();
        for (int i=0;i<50;i++){
            new Thread(new OrderService()).start();
        }
        try {
            countDownLatch.await();
        }catch (Exception e){
            e.printStackTrace();
        }

        for (String str:result) {
            System.out.println(str);
        }

    }

}
